package top.chatgqt.SmartChargeStation.mqtt.client.factory;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
import top.chatgqt.SmartChargeStation.mqtt.client.conf.MqttProps;


/*
 * MQTT 工厂类
 */
@Configuration
@Slf4j
public class FactoryBuilder {

    @Resource
    private MqttProps mqttProps;

    /**
     * 获取mqtt客户端
     */
    public MqttPahoClientFactory getClientFactory() {
        DefaultMqttPahoClientFactory clientFactory = new DefaultMqttPahoClientFactory();

        MqttConnectOptions options = mqttProps.getOptions();
        options.setServerURIs(new String[]{mqttProps.getHost()});
        clientFactory.setConnectionOptions(options);
        return clientFactory;
    }
}
